package day16;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 需求：
 * 每一个学生都有一个归属地
 * 学生Student，地址String
 * 学生属性：姓名，年龄
 * 注意：学生姓名和年龄视为同一个对象
 * 保证学生的唯一性
 * @author wangbiao
 *
 */
public class MapTest {

	public static void main(String[] args) {
		
		Map<Student, String> map = new HashMap<Student, String>();
		map.put(new Student("wangwu", 21), "shanghai");
		map.put(new Student("wangbiao", 25), "shanghai");
		map.put(new Student("wangwu", 23), "beijing");
		map.put(new Student("wangxiaoer", 21), "chengdu");
		map.put(new Student("wangsan", 22), "shanghai");
	
		//keySet
		Set<Student> keySet = map.keySet();
		for (Iterator<Student> iterator = keySet.iterator(); iterator.hasNext();) {
			Student student = iterator.next();
			String value = map.get(student);
			System.out.println(student +"-->"+value);
		}
		//entrySet
		Set<Entry<Student, String>> entrySet = map.entrySet();
		for (Iterator<Entry<Student,String>> iterator = entrySet.iterator(); iterator.hasNext();) {
			Entry<Student, String> entry = iterator.next();
			Student key = entry.getKey();
			String value = entry.getValue();
			System.out.println(key + "--->" + value);
		}
	}
}
